package net.wsfcp.android.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import net.wsfcp.android.R;
import net.wsfcp.android.bean.resultbean.OrderBean;

import java.util.ArrayList;
import java.util.List;


//订单二级商品列表
public class OrderListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    ArrayList<OrderBean.OrderList.Order2GoodsList> order2Lists;

    Context mContext;
    LayoutInflater mInflater;

    public OrderListAdapter(ArrayList<OrderBean.OrderList.Order2GoodsList> orderLists, Context context) {
        this.order2Lists = orderLists;
        this.mContext = context;
        mInflater = LayoutInflater.from(mContext);
    }


    public List<OrderBean.OrderList.Order2GoodsList> getOrder2Lists() {
        return order2Lists;
    }

    public void setOrderLists(ArrayList<OrderBean.OrderList.Order2GoodsList> orderLists) {
        this.order2Lists = orderLists;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_list_order_listitem, parent, false);
        return new ItemViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        OrderBean.OrderList.Order2GoodsList bean = order2Lists.get(position);
        viewHolder.txt_goods_name.setText(bean.getGoodsName());
        Glide.with(mContext).load(bean.getGoodsImageUrl()).apply(new RequestOptions().placeholder(R.mipmap.ic_launcher)).into(viewHolder.img);
        viewHolder.txt_num.setText(bean.getBuyNum() + "");
        viewHolder.txt_price.setText(bean.getShowUnitPrice() + "");


    }

    @Override
    public int getItemCount() {
        return order2Lists.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {

        TextView txt_goods_name;
        ImageView img;
        TextView txt_num;
        TextView txt_price;

//            CardView llItem;

        public ItemViewHolder(View itemView) {
            super(itemView);

            txt_goods_name = itemView.findViewById(R.id.txt_goods_name);
            img = itemView.findViewById(R.id.img);
            txt_num = itemView.findViewById(R.id.txt_num);
            txt_price = itemView.findViewById(R.id.txt_price);

//                llItem = itemView.findViewById(R.id.llItem);
        }
    }
}
